import os

def extract_code_from_files(folder, extension):
    """
    递归遍历文件夹并提取指定扩展名的代码。
    """
    code_snippets = []
    for root, dirs, files in os.walk(folder):
        for file in files:
            if file.endswith(extension):
                file_path = os.path.join(root, file)
                with open(file_path, 'r', encoding='utf-8') as f:
                    code_snippets.append(f.read())
    return code_snippets
